#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDataStream>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    server = new QTcpServer(this);
    server->listen(QHostAddress("192.168.5.149"),11111);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::onNewConnection()
{
    socket = server->nextPendingConnection();

}

void MainWindow::onReadyRead()
{
    while(socket->bytesAvailable() > 0)
    {
        QString string;
        QDataStream reader(socket);
        reader >> string;

        qDebug() << string;

        if(string == "forward")
        {
            //功能处理
        }

    }
}


void MainWindow::on_pushButton_clicked()
{
    QString msg = "forward";
    QDataStream writer(socket);
    writer << msg;
}

